<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<link rel="stylesheet" type="text/css" media="screen" href="styles/grid/css/ui-lightness/jquery-ui-1.8.17.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="styles/grid/css/ui.jqgrid.css" />
<script type="text/javascript" src="styles/support/ajaxFrmSbmt.js"></script>
<link rel="stylesheet" href="styles/popup/general_FU.css" type="text/css" media="screen" />
<script src="styles/grid/js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="styles/grid/js/i18n/grid.locale-es.js" type="text/javascript"></script>
<script src="styles/grid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="styles/grid/js/i18n/grid.locale-es.js" type="text/javascript"></script>
<script src="styles/grid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="styles/popup/popup_FU.js" type="text/javascript"></script>
<script type="text/javascript" src="styles/support/indec.js"></script>

<style type="text/css">
	.ui-jqgrid tr.jqgrow td {font-size:0.8em}
	.ui-pg-table {font-size:1em}
	.ui-jqgrid-titlebar-close {display: none;}	
	#jqgh_list_cuit {height: 25px;}
	#jqgh_list_campaign {height: 25px;}
	#jqgh_list_status {height: 25px;}
	#jqgh_list_download {height: 25px;}
	#jqgh_list_upload {height: 25px;}
</style>

<script type="text/javascript">

	function performAjaxSubmit() {
		var sampleText = document.getElementById("companyCampaignID").value;
		var sampleFile = document.getElementById("fileUploadName").files[0];
		
		var formdata = new FormData();
		formdata.append("id", sampleText);
		formdata.append("file", sampleFile);	        		
		
		var xhr = new XMLHttpRequest();
		
		xhr.open("POST","executeAction?action=uploadPoll", true);
		xhr.send(formdata);
		
		xhr.onload = function(e) {
				if (this.status == 200) {
				   alert(this.responseText);
				}
		};
	}

	
	
	function load() {
		jQuery("#list").jqGrid(
				{
					width : '960',					
					height: '400',					
					url : '<%=request.getContextPath()%>/getJsonGrid?gridName=GET_CC',
					datatype : "json",
					colNames : [ 'Cuit de la Empresa', 'Operativo','Estado','Descargar','Actualizar'],
					colModel : [ {
						name : 'cuit',
						index : 'cuit',
						width : 200,
						sortable: true,
						sorttype: 'int',
						align: 'center'	
					}, {
						name : 'campaign',
						index : 'campaign',
						width : 300,
						sortable: true,
						align: 'center'
					}, {
						name : 'status',
						index : 'status',
						width : 200,
						sortable: true,
						align: 'center'
					} ,{
						name : 'download',
						index : 'download',
						width : 100,
						sortable: false,
						search: false,
						formatter: 'showlink',
						formatoptions:{baseLinkUrl:'./executeAction', addParam: '&action=downloadPoll', target: 'sommaire'},
						align: 'center'
					} ,{
						name : 'upload',
						index : 'upload',
						width : 100,
						sortable: false,
						search: false,
						formatter: 'showlink',
						//formatoptions:{baseLinkUrl:'./executeAction', addParam: '&action=uploadPollsss" onclick="alert(\'prueba\');', target: 'sommaire'},
						formatoptions:{baseLinkUrl:'', addParam: '" onclick="centerPopup();loadPopup();return false;', target: 'sommaire'},
						align: 'center'
					} ],
					rowNum : 10,
					rowList : [ 10, 20, 30],
					imgpath : 'includes/css/ui-lightness/images',
					pager : jQuery('#pager'),
					sortname : 'cuit',
					sortable : true,
					sortorder : 'asc',
					viewrecords : true,					
					caption : " ",
					loadonce: true,
					onSelectRow: function(id){ 
					if(id){
						jQuery("#openPollsBtn").attr("disabled",false);
						var selectedRow = jQuery("#list").jqGrid('getGridParam','selrow');
						jQuery("#companyCampaignID").val(selectedRow);
					}
			   }
				}).navGrid('#pager', {
			edit : false,
			add : false,
			del : false, 
			search:true,
			beforeRefresh: function()
			{
				jQuery("#list").jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');
			}
		});
		//jQuery("#list").trigger('reloadGrid');
		jQuery("#openPollsBtn").click( function() {
			var selectedRow = jQuery("#list").jqGrid('getGridParam','selrow');
			if(selectedRow != null)
			{
				window.open('./menu?id=' + selectedRow,'main');//,"status=0, status='NO', directories=0, menubar=0, personalbar=0, directories=0, toolbar=0, location=0, scrollbars=1, dependent='YES', resizable='YES', resizable=1, width=600, height=400, top=100, left=100");
			}
		});
	}
</script>
</head>
<body onload="javascript:load()" >

	<div align="center"> <img src='styles/img/CargarRel.png'/> </div>
	<div id="content" style="width: 1000px;">			 
		<h1 style="padding-left: 20px;padding-top: 10px; margin: auto">Seleccione una encuesta</h1>
		<div style="padding-left: 20px;padding-top: 20px; margin: auto">
			<table id="list" class="scroll"></table>
			<div id="pager" class="scroll" style="text-align:center;"></div>
			<br />
			<div style="text-align: right">
				<input type="button" id="openPollsBtn" disabled="disabled" value="Visualizar" class="fg-button ui-state-default ui-corner-all" />
			</div>	
		</div>
		<div id="backgroundPopup"></div>
		<div id="popup">
			<a id="popupClose">x</a>
			<div id="titleArea" align="center"><h1>Seleccione el archivo</h1></div>		
	<!--		<form method="post" enctype="multipart/form-data; boundary=AaB03x" name="formFileUpload" id="formFileUpload" onsubmit="getxmlHttpRequestFileUpload('executeAction?action=uploadPoll', 'formFileUpload', 'message', 'wait'); return false;"> -->
			<form>
				<input type="hidden" id="companyCampaignID" name="companyCampaignID" value="" />
				<div id="uploadArea">
					<input type="file" name="fileUploadName" id="fileUploadName" class="fg-button ui-state-default ui-corner-all">
					<br/>
					<br/>
					<input type="button" onclick="getXmlHttpRequestUpdatePoll();" name="fileUploadButton" id="fileUploadButton" value="Cargar" class="fg-button ui-state-default ui-corner-all">
				</div>
				<div id="messageArea">
					<div id="saveComment" class="save"></div>
					<div id="SaveArea" align="center"></div>
				</div>
			</form> 
		</div>
	</div>
</body>
</html>